package cc.idoone.springframework.placeholder.xml;

import java.util.Map;

/**
 * 文件上传配置
 *
 * @author hemj
 * @date 2018-05-17
 */
public class UploadRule {
    /**
     * 文档分类
     */
    private String category;
    /**
     * 存储类型: disk,oss
     */
    private String storeMedia;
    /**
     * 存储位置名称
     */
    private String storeBucket;
    /**
     * 存储位置 for disk
     */
    private String storeHome;
    /**
     * 存储位置 for oss
     */
    private String ossBucket;
    /**
     * 保存路径
     */
    private String storePath;
    /**
     * 子目录(日期)格式化
     */
    private String dateFormat;
    /**
     * 允许上传类型与大小限制
     */
    private Map<String, Integer> allowTypes;
    /**
     * 文档上传成功后的访问地址前缀
     */
    private String downloadPrefix;
    /**
     * 文档上传成功后的访问地址是否需要签名
     */
    private String downloadPresigned;
    /**
     * 默认配置
     */
    private UploadRule defaultUploadRule;

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getStoreMedia() {
        if (storeMedia != null) {
            return storeMedia;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.storeMedia;
    }

    public void setStoreMedia(String storeMedia) {
        this.storeMedia = storeMedia;
    }

    public String getStoreBucket() {
        if (storeBucket != null) {
            return storeBucket;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.storeBucket;
    }

    public void setStoreBucket(String storeBucket) {
        this.storeBucket = storeBucket;
    }

    public String getStoreHome() {
        if (storeHome != null) {
            return storeHome;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.storeHome;
    }

    public void setStoreHome(String storeHome) {
        this.storeHome = storeHome;
    }

    public String getOssBucket() {
        if (ossBucket != null) {
            return ossBucket;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.ossBucket;
    }

    public void setOssBucket(String ossBucket) {
        this.ossBucket = ossBucket;
    }

    public String getStorePath() {
        if (storePath != null) {
            return storePath;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.storePath;
    }

    public void setStorePath(String storePath) {
        this.storePath = storePath;
    }

    public String getDateFormat() {
        if (dateFormat != null) {
            return dateFormat;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.dateFormat;
    }

    public void setDateFormat(String dateFormat) {
        this.dateFormat = dateFormat;
    }

    public Map<String, Integer> getAllowTypes() {
        if (allowTypes != null) {
            return allowTypes;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.allowTypes;
    }

    public void setAllowTypes(Map<String, Integer> allowTypes) {
        this.allowTypes = allowTypes;
    }

    public String getDownloadPrefix() {
        if (downloadPrefix != null) {
            return downloadPrefix;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.downloadPrefix;
    }

    public void setDownloadPrefix(String downloadPrefix) {
        this.downloadPrefix = downloadPrefix;
    }

    public String getDownloadPresigned() {
        if (downloadPresigned != null) {
            return downloadPresigned;
        }
        return defaultUploadRule == null ? null : defaultUploadRule.downloadPresigned;
    }

    public void setDownloadPresigned(String downloadPresigned) {
        this.downloadPresigned = downloadPresigned;
    }

    public UploadRule getDefaultUploadRule() {
        return defaultUploadRule;
    }

    public void setDefaultUploadRule(UploadRule defaultUploadRule) {
        this.defaultUploadRule = defaultUploadRule;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UploadRule that = (UploadRule) o;

        return category.equals(that.category);
    }

    @Override
    public int hashCode() {
        return category.hashCode();
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("\nUploadConfig{");
        sb.append("category='").append(category).append('\'');
        sb.append(", storeMedia='").append(storeMedia).append('\'');
        sb.append(", storeBucket='").append(storeBucket).append('\'');
        sb.append(", storeHome='").append(storeHome).append('\'');
        sb.append(", ossBucket='").append(ossBucket).append('\'');
        sb.append(", storePath='").append(storePath).append('\'');
        sb.append(", dateFormat='").append(dateFormat).append('\'');
        sb.append(", allowTypes=").append(allowTypes);
        sb.append(", downloadPrefix='").append(downloadPrefix).append('\'');
        sb.append(", downloadPresigned='").append(downloadPresigned).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
